package com.goods.webservice.controller;

import com.goods.povos.WeatherPovo;
import com.goods.utools.ipconversion.IPUtils;
import com.goods.utools.ipcustomer.IPCustomer;
import com.goods.webservice.service.WebServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/WebService")
public class WebServiceController {
    @Autowired
    private WebServiceService webServiceService;

    @RequestMapping("/GetWeather")
    @ResponseBody
    public WeatherPovo getWeather(String  city) {
//        将地址传递至服务
        WeatherPovo povo = webServiceService.getWeater(city);
//        返回城市
        return povo;
    }


    //    获取当地天气信息Test
    @RequestMapping("/Weather")
    public String weather(HttpServletRequest request, Model model) {
//        获取请求的ip
        String ip = IPCustomer.getIpAddr(request);
        System.out.println(ip);
//        ip转地址
        String address = IPUtils.getCityInfo(ip);
        System.out.println(address);
//        将地址传递至服务
        List<String> weather = webServiceService.weater(address);
        model.addAttribute("weather", weather);
        return "jsps/webservice/weather";
    }


    //    获取英文翻译
    @RequestMapping("/EnglishChinese")
    public String englishChinese(String wordKey, Model model) {
        List<String> list = webServiceService.english(wordKey);
        model.addAttribute("list", list);
        return "jsps/webservice/EnglishChinese";
    }

    //    获取英文翻译MP3字节流
    @RequestMapping("/EnglishChineseMP3")
    @ResponseBody
    public byte[] englishChineseMP3(String mp3) {
        byte[] mp31 = webServiceService.englishChineseMP3(mp3);
        return mp31;
    }

    //  获取手机号归属地
    @RequestMapping("/SelectMobile")
    public String selectMobile(String mobile, Model model) {
        String res = webServiceService.selectMobile(mobile);
        model.addAttribute("res", res);
        return "jsps/webservice/mobile";
    }


}
